package com.hnair.grpc.example.configuration;

import com.hnair.grpc.example.interceptor.LogGrpcInterceptor;
import com.github.grpc.server.service.GlobalServerInterceptorConfigurerAdapter;
import com.github.grpc.server.service.GlobalServerInterceptorRegistry;
import com.hnair.grpc.example.interceptor.TokenInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GlobalInterceptorConfiguration {

    private static final Logger logger = LoggerFactory.getLogger(GlobalInterceptorConfiguration.class);

    @Bean
    public GlobalServerInterceptorConfigurerAdapter globalInterceptorConfigurerAdapter() {
        return new GlobalServerInterceptorConfigurerAdapter() {
            @Override
            public void addServerInterceptors(GlobalServerInterceptorRegistry registry) {
                logger.debug("addServerInterceptors ......");
                registry.addServerInterceptors(new LogGrpcInterceptor());
                registry.addServerInterceptors(new TokenInterceptor());
            }
        };
    }

}